package com.jams.log.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jams.common.core.system.JamsResponse;
import com.jams.common.security.annotation.Inner;
import com.jams.log.api.entity.SysLog;
import com.jams.log.service.SysLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 日志表
 *
 * @author linxb
 * @date 2020-03-30 15:52:34
 */
@RestController
@AllArgsConstructor
@RequestMapping("/syslog")
@Api(value = "syslog", tags = "日志表管理")
public class SysLogController {

    private final  SysLogService sysLogService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param sysLog 日志表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public JamsResponse getSysLogPage(Page page, SysLog sysLog) {
        return JamsResponse.ok(sysLogService.page(page, Wrappers.query(sysLog)));
    }

    /**
     * 列表查询
     * @param sysLog 日志表
     * @return
     */
    @ApiOperation(value = "列表查询", notes = "列表查询")
    @PostMapping("/list")
    public JamsResponse getSysLogList(SysLog sysLog) {
        return JamsResponse.ok(sysLogService.list(Wrappers.query(sysLog)));
    }

    /**
     * 通过id查询日志表
     * @param id id
     * @return JamsResponse
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public JamsResponse getById(@PathVariable("id") Long id) {
        return JamsResponse.ok(sysLogService.getById(id));
    }

    /**
     * 新增日志表
     * @param sysLog 日志表
     * @return JamsResponse
     */
    @Inner
    @ApiOperation(value = "新增日志表", notes = "新增日志表")
    @PostMapping("/save")
    public JamsResponse save(@RequestBody SysLog sysLog) {
        return JamsResponse.ok(sysLogService.save(sysLog));
    }

    /**
     * 修改日志表
     * @param sysLog 日志表
     * @return JamsResponse
     */
    @ApiOperation(value = "修改日志表", notes = "修改日志表")
    @PostMapping("/update")
    public JamsResponse updateById(@RequestBody SysLog sysLog) {
        return JamsResponse.ok(sysLogService.updateById(sysLog));
    }

    /**
     * 通过id删除日志表
     * @param id id
     * @return JamsResponse
     */
    @ApiOperation(value = "通过id删除日志表", notes = "通过id删除日志表")
    @GetMapping("/delete/{id}")
    public JamsResponse removeById(@PathVariable Long id) {
        return JamsResponse.ok(sysLogService.removeById(id));
    }

}
